﻿using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace ERPStore.Cart.Repositories.Mapping
{
	public class CartMap : EntityTypeConfiguration<Datas.Cart>
	{
		public CartMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);
            this.Property(e => e.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);

			// Properties
			this.Property(t => t.VisitorId)
				.IsRequired()
				.HasMaxLength(40);
				
			this.Property(t => t.CustomerDocumentReference)
				.HasMaxLength(100);
				
			this.Property(t => t.Code)
				.IsRequired()
				.HasMaxLength(40);
				
			
			this.Property(t => t.LastPage)
				.HasMaxLength(255);
				
			this.Property(t => t.PaymentModeName)
				.HasMaxLength(50);
				
			this.Property(t => t.LeadSourceName)
				.HasMaxLength(512);
				
			this.Property(t => t.LeadSourceId)
				.HasMaxLength(50);
				
			this.Property(t => t.RevisionId)
				.IsRequired()
				.IsFixedLength()
                .IsConcurrencyToken()
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)
				.HasMaxLength(8);

			this.Property(t => t.MessageForConveyor)
				.IsOptional()
				.IsMaxLength();
				
			// Table & Column Mappings
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.CreationDate).HasColumnName("CreationDate");
			this.Property(t => t.VisitorId).HasColumnName("VisitorId");
			this.Property(t => t.CartStateId).HasColumnName("CartStateId");
			this.Property(t => t.CustomerId).HasColumnName("CustomerId");
			this.Property(t => t.CustomerPersonId).HasColumnName("CustomerPersonId");
			this.Property(t => t.Message).HasColumnName("Message");
			this.Property(t => t.AllowPartialDelivery).HasColumnName("AllowPartialDelivery");
			this.Property(t => t.IsPresent).HasColumnName("IsPresent");
			this.Property(t => t.CustomerDocumentReference).HasColumnName("CustomerDocumentReference");
			this.Property(t => t.LastUpdate).HasColumnName("LastUpdate");
			this.Property(t => t.Code).HasColumnName("Code");
			this.Property(t => t.DeliveryAddressId).HasColumnName("DeliveryAddressId");
			this.Property(t => t.ShippingFeeAmount).HasColumnName("ShippingFeeAmount");
			this.Property(t => t.ShippingFeeTaxRate).HasColumnName("ShippingFeeTaxRate");
			this.Property(t => t.ConvertedEntityId).HasColumnName("ConvertedEntityId");
			this.Property(t => t.ConversionDate).HasColumnName("ConversionDate");
			this.Property(t => t.ConveyorId).HasColumnName("ConveyorId");
			this.Property(t => t.AcceptTermsAndConditions).HasColumnName("AcceptTermsAndConditions");
			this.Property(t => t.LastPage).HasColumnName("LastPage");
			this.Property(t => t.FromEntityId).HasColumnName("FromEntityId");
			this.Property(t => t.FromMetaEntityId).HasColumnName("FromMetaEntityId");
			this.Property(t => t.PaymentModeName).HasColumnName("PaymentModeName");
			this.Property(t => t.LeadSourceName).HasColumnName("LeadSourceName");
			this.Property(t => t.LeadSourceId).HasColumnName("LeadSourceId");
			this.Property(t => t.RevisionId).HasColumnName("RevisionId");
			this.Property(t => t.ShippingFeeLocked).HasColumnName("ShippingFeeLocked");

			this.ToTable("Cart");
		}
	}
}

